var model = {
	user: "Adam",
	items: [{
		action: "Buy Flowers",
		done: false
	}, {
		action: "Get Shoes",
		done: false
	}, {
		action: "Collect Tickets",
		done: true
	}, {
		action: "Call Joe",
		done: false
	}]
};

var todoApp = angular.module("todoApp", []);


todoApp.run(function ($http) {
	$http.get("a.json")
	.success(function (data) {
			model.items = data;
	})
	.error(function(d){
	  alert('Error'+d);
	});
});

todoApp.filter("checkedItems", function () {
	return function (items, showComplete) {
	var resultArr = [];
	angular.forEach(items, function (item) {
	if (item.done == false || showComplete == true) {
	resultArr.push(item);
	}
	});
	return resultArr;
	}
});

todoApp.controller("ToDoCtrl", function($scope) {
	$scope.todo = model;
	$scope.inputInfo = "Helloworld";

	$scope.incompleteCount = function() {
		var count = 0;
		angular.forEach($scope.todo.items, function(item) {
			if (item.done) {
				count++
			}
		});
		return count;
	};

	$scope.add = function(inputInfo) {
		$scope.todo.items.push({action:inputInfo,done:false});
	};

	$scope.warningLevel = function() {
		return $scope.incompleteCount() < 3 ? "label-success" : "label-warning";
	};
	
 
});